<template>
<div class="select">
  <van-index-bar :index-list="indexList">
    <template v-for="(item,name) in cityArr">
      <van-index-anchor :index="name"  :key="name"/>
      <van-cell :title="ele.name" v-for="ele in item" :key="ele.id" @click="titleClick"/>
    </template>
  </van-index-bar>
</div>
</template>

<script>
import api from '@/api/index'
export default {
  data(){
    return{
      cityArr:{},
      indexList:[],
      city:''
    }
  },
created() {
  api.getSelectData()
  .then(res=>{
    // console.log(res.data)
    this.cityArr=res.data.result.citylist
    this.indexList=Object.keys(this.cityArr)
  })
},
  methods:{
    titleClick(event){
      // console.log(event)
      this.city=event.target.innerText
      // console.log(this.city)
      localStorage.setItem('city',this.city)
      this.$router.go(-1)
    }
  }
}
</script>

<style lang="less" scoped>

</style>

